// pages/mine/shop/mycard/mycarddetail.js
const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    info: null,
    id: '',
    nav: [
      { title: '充值', icon: 'gif', url: 'cardrecharge', color_id: 7 },
      { title: '充次', icon: 'gouwudai', url: 'cardnum', color_id: 5 },
     
      { title: '消费记录', icon: 'log', url: 'paylist', color_id: 2 },
      { title: '充值记录', icon: 'log', url: 'loglist', color_id: 4 },

      { title: '充次记录', icon: 'log', url: 'meallist', color_id: 7 },
      { title: '计次信息', icon: 'log', url: 'mealpay', color_id: 6 },
      { title: '积分记录', icon: 'edit', url: 'chargelist', color_id: 5 },
      { title: '优惠券', icon: 'video', url: 'mymeal', color_id: 7 },
      { title: '积分商城', icon: 'doc', url: '/pages/creditshop/shop_goodlist', color_id: 8 },
      { title: '关联其他商家优惠', icon: 'bbs', url: 'linkcard', color_id: 9 },
      { title: '推荐奖', icon: 'edit', url: 'recommend', color_id: 5 },
      
    ],
  

  },
  backto: function (e) {
    wx.navigateBack({})
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    let extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {};
    that.setData({
      card_id: options.id,
      token: extConfig.appid
      
    });

  },
  // 获取 会员卡的相关信息
  getCard: function () {
    let that = this;
    app.ihttpGet('https://www.58zltc.com/api.php/MyCard/mycard/openid/' + app.globalData.openid +'/card_id/'+that.data.card_id, function (res) {
      that.setData({
        card: res.data.card,
        mycard: res.data.mycard,
        count:res.data.count,
      })
      wx.hideLoading();
    });
  },
  qrcode: function (e) {
    wx.showLoading({
      title: '拼命生成中',
    })
    var that = this

    var url = 'https://www.58zltc.com/api.php/Qrcode/getPayCode/card_id/' + that.data.card_id + '/token/' + that.data.token;
    var urls = [];
    urls.push(url);
    wx.previewImage({
      urls: urls
    })


    wx.hideLoading();

  },

  jump: function (options) {
    let that = this;
    var url = options.currentTarget.dataset.url;
    var id = options.currentTarget.dataset.id;
    if (url == 'add') {
      url = url + "?type=edit&id=" + that.data.card_id;
    } 
    else if (url == '/pages/creditshop/shop_goodlist'){
      url = url + "?shop_id="+that.data.card.shop_id
    }
    else {
      url = url + "?id=" + that.data.card_id + '&openid=' + app.globalData.openid;
    }

    console.log(url)

    wx.navigateTo({
      url: url,
    })
  },
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this;

    wx.showLoading({
      title: '加载中…',
    })
  
    this.getCard();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  hiden_agreement: function () {
    var that = this
    this.setData({
      showShopJoinAgreement: 0
    })
    wx.navigateTo({
      url: './card/joincard?shop_id=' + that.data.shop_id,
    })
  }
})